package com.gdth.widget.dialog;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class DialogView{

	/**************选择提示框*************/
	private ProgressDialog progressDialog;
	
	private DialogConfig mConfig;
	
	private DialogPrompt mPrompt;
	
	private static DialogView instance = null;
	
    public static DialogView getInstance(){  
       if (instance == null) {  
    	   instance = new DialogView();
       }  
       return instance;
    }
    
	private DialogView(){  
	       // Exists only to defeat instantiation.  
    }
	
	/**
	 * 弹出提示框
	 * @param title
	 * @param val
	 */
	public void progressShow(Context context, String title, String val){
		progressDialog = ProgressDialog.show(context, title, val, true);
	}
	
	/**
	 * 隐藏提示框
	 */
    public void progressHide(){
    	if (progressDialog != null)
    		progressDialog.dismiss();
	}
	
    public void showConfigDialog(Context context, String value){
    	if (mConfig == null){
    		mConfig = new DialogConfig(context, value, false);
    	}
    	
    	mConfig.show();
    }
    
    public void dismissConfig(){
    	if (mConfig != null)
    		mConfig.dismiss();
    }
    
    public void showmPromptDialog(Context context, String value){
    	if (mPrompt == null){
    		mPrompt = new DialogPrompt(context, value);
    	}
    	
    	mPrompt.show();
    }
    
    public void dismissPrompt(){
    	if (mPrompt != null)
	    	mPrompt.dismiss();
    }
	/**************退出事件*************/
    /**
     * 退出标志
     */
	private static boolean isExit;
	
	/**
	 * 退出事件
	 * @param context
	 */
	public static void exit(Context context){  
        if (!isExit) {
            isExit = true;
            Toast.makeText(context, "再按一次退出程序", Toast.LENGTH_SHORT).show();  
            exitHandler.sendEmptyMessageDelayed(0, 2000);  
        } else {
            Intent intent = new Intent(Intent.ACTION_MAIN);  
            intent.addCategory(Intent.CATEGORY_HOME);  
            context.startActivity(intent);  
            System.exit(0);  
        }
    }
	
	static Handler exitHandler = new Handler(new Handler.Callback(){
		@Override
		public boolean handleMessage(Message msg) {
			isExit = false; 
			return false;
		}
	});
}